<!DOCTYPE html>
<html>
<head>
    <!-- from: https://phaser.io/sandbox/frame -->
    <meta charset="utf-8" />
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="gsw945" />
    <link rel="shortcut icon" type="image/x-icon" href="./favicon.ico" />
    <title>Phaser Demo With Parcel</title>
    <link rel="stylesheet" href="styles.css" />
    <style type="text/css">
        body,
        html {
            margin: 0;
            padding: 0;
            border: 0;
        }
        #game {
            border: 1px solid #fa1;
        }
    </style>
</head>
<body>
    <!-- <h1>Hello, World!</h1> -->
    <div class="page-body">
        <div id="game"></div>
    </div>
    <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.5.1/jquery.min.js" type="text/javascript"></script>
    <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/phaser/3.52.0/phaser.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var config = {
            type: Phaser.AUTO,
            parent: 'game',
            width: 800,
            height: 600,
            backgroundColor: 0x2d2d2d,
            physics: {
                default: 'arcade',
                arcade: {
                    gravity: { y: 200 }
                }
            },
            scene: {
                preload: preload,
                create: create,
                update: update,
                render: render
            }
        };

        var bob;
        var graphics;
        var offset;

        var game = new Phaser.Game(config);

        function preload ()
        {
            // this.load.setBaseURL('http://labs.phaser.io');
            
            this.load.image('pic', 'assets/pics/skull-and-bones.jpg');
        }

        function create ()
        {
            // this.add.image(0, 0, 'pic').setAlpha(0.3);

            bob = this.add.image(0, 0, 'pic').setOrigin(0, 0);

            graphics = this.add.graphics({
                lineStyle: {
                    width: 1,
                    color: 0xaa00aa
                },
                fillStyle: {
                    color: 0x0000aa
                }
            });

            var cropWidth = 200;
            var cropHeight = 100;

            bob.setCrop(0, 0, cropWidth, cropHeight);

            offset = bob.getTopLeft();

            this.input.on('pointermove', function (pointer) {

                bob.setCrop(
                    (pointer.x - offset.x) - cropWidth / 2,
                    (pointer.y - offset.y) - cropHeight / 2,
                    cropWidth,
                    cropHeight
                );
            });
        }

        function update ()
        {
            graphics.clear();
            graphics.lineStyle(1, 0x00ff00);
            graphics.strokeRect(offset.x + bob._crop.x, offset.y + bob._crop.y, bob._crop.width, bob._crop.height);
        }

        function render () {
            //
        }
    </script>
</body>
</html>